Manipulate Object Repositories - Example
Manipulate object repositories using the Object Repository Automation objects and methods.
Dim ImageObj, PageObj, RepositoryFrom, RepositoryTo
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil") Set RepositoryTo = CreateObject("Mercury.ObjectRepositoryUtil")
RepositoryFrom.Load "C:\UFT One\Tests\Flights.tsr" RepositoryTo.Load "E:\Temp\Tests\Default.tsr" Function EnumerateAllChildProperties(Root)
Dim TOCollection, TestObject, PropertiesCollection, Property, Msg
Set TOCollection = RepositoryFrom.GetChildren(Root)
For i = 0 To TOCollection.Count - 1 Set TestObject = TOCollection.Item(i) Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine Set PropertiesCollection = TestObject.GetTOProperties()
For n = 0 To PropertiesCollection.Count - 1 SetProperty = PropertiesCollection.Item(n) Msg = Msg & Property.Name & "-" & Property.Value & vbNewLine Next MsgBox Msg
EnumerateAllChildProperties TestObject Next
EndFunction
Function EnumerateAllObjectsProperties(Root)
Dim TOCollection, TestObject, PropertiesCollection, Property, Msg
Set TOCollection = RepositoryFrom.GetAllObjects(Root)
For i = 0 To TOCollection.Count - 1 Set TestObject = TOCollection.Item(i) Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine
Set PropertiesCollection = TestObject.GetTOProperties() For n = 0 To PropertiesCollection.Count - 1 SetProperty = PropertiesCollection.Item(n) Msg = Property.Name & "-" & Property.Value & vbNewLine Next
MsgBox Msg Next
EndFunction
Function RenameAllImages(Root)
Dim TOCollection, TestObject, PropertiesCollection, Property
Set TOCollection = RepositoryTo.GetAllObjectsByClass("Image")
For i = 0 To TOCollection.Count - 1 Set TestObject = TOCollection.Item(i) RepositoryTo.RenameObject (TestObject, "Image " & i) RepositoryTo.UpdateObject TestObject Next
EndFunction
Function RemoveAllLinks(Root)
Dim TOCollection, TestObject, PropertiesCollection, Property
Set TOCollection = RepositoryFrom.GetChildren(Root)
For i = 0 To TOCollection.Count - 1 Set TestObject = TOCollection.Item(i) TOClass = TestObject.GetTOProperty("micclass")
If TOClass = "Link"Then RepositoryFrom.RemoveObject Root, TestObject EndIf
EnumerateAllChildProperties TestObject Next
EndFunction
|